#!/usr/bin/python
# coding=utf8

__version__ = '0.1.0'
__author__  = "Eugene Frolov"
__mail__    = "profisphantom@gmail.com"


from SimpleXMLRPCServer import CGIXMLRPCRequestHandler
from database import Storage
import pickle


class TableEngine(object):
    
    def __init__(self):
        self.storage = Storage()
    
    def get_client(self, id):
        return self.storage.get_table_value('Client', id, 'name')
    
    def get_address(self, id):
        return self.storage.get_table_value('Address', id, 'address')
    
    def get_model(self, id):
        return self.storage.get_table_value('Model', id, 'name')
    
    def get_disign(self, id):
        return self.storage.get_table_value('Disign', id, 'name')
    
    def get_warranty(self, id):
        return self.storage.get_table_value('Warranty', id, 'periud')
#    
#    def get_main(self):
#        return {'main': self.storage.get_main()}
#    
    def register_search(self, param):
        return self.storage.search_save(param)
#    
    def save_main(self, adate, aclient, aaddress, amodel, adisign, awarranty, 
                  attn, aschet, acode, acomment, silist):
        return self.storage.save_main(adate, aclient, aaddress, amodel, adisign, 
            awarranty, attn, aschet, acode, acomment, silist)
    
    def check_ident(self, serial_number, inventory_number):
        return self.storage.check_ident(serial_number, inventory_number)
    
    def xls(self, qid):
        return self.storage.xls_export(qid);
    
    def delete_items(self, arr):
        return self.storage.delete_items(arr)


handler = CGIXMLRPCRequestHandler()
handler.register_function(lambda x,y: x+y, 'add')
handler.register_instance(TableEngine())
handler.register_introspection_functions()
handler.handle_request()